package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/5 11:04
 */
public class ReputationAdapter extends BaseRecyclerAdapter<ReputationAdapter.Holder, ReputationAdapter.Reputation> {
    private final String TAG = "ReputationAdapter";


    public ReputationAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_reputation;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        final int index = position;
        final Reputation entity = data.get(index);
        Glide.with(context).load(entity.icon).into(holder.iconIv);
        holder.nameTv.setText(entity.name);
        holder.scoreTv.setText(entity.score);
        holder.buttonTv.setOnClickListener(v -> {
            if (itemClickListener != null) {
                itemClickListener.onViewClick(v, "button", index, entity);
            }
        });
    }

    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.icon_iv)
        ImageView iconIv;
        @BindView(R.id.name_tv)
        TextView nameTv;
        @BindView(R.id.score_tv)
        TextView scoreTv;
        @BindView(R.id.button_tv)
        TextView buttonTv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public static class Reputation {
        Object icon;
        String name;
        String score;

        public Object getIcon() {
            return icon;
        }

        public void setIcon(Object icon) {
            this.icon = icon;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getScore() {
            return score;
        }

        public void setScore(String score) {
            this.score = score;
        }
    }

}
